package cn.devices.service.impl;

import cn.devices.entity.TbAdm;
import cn.devices.mapper.TbAdmMapper;
import cn.devices.service.TbAdmService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author 秋水浮萍
 * @since 2021-02-07
 */
@Service
public class TbAdmServiceImpl implements TbAdmService {

    @Autowired
    private TbAdmMapper mapper;


    @Override
    public TbAdm getByAdmId(Integer admId) {
        return mapper.getByAdmId(admId);
    }

    @Override
    public TbAdm getByUP(String loginName, String loginPass) {
        return mapper.getByUP(loginName, loginPass);
    }

    @Override
    public TbAdm getByLoginName(String loginName) {
        return mapper.getByLoginName(loginName);
    }

    @Override
    public String loginPassCorrect(Integer admId) {

        return mapper.loginPassCorrect(admId);
    }

    @Override
    public int loginPassUpdate(Integer admId, String loginPassNew) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String password = passwordEncoder.encode(loginPassNew);
        return mapper.loginPassUpdate(admId, password);
    }

    @Override
    public int tbAdmAdd(TbAdm tbAdm) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        tbAdm.setLoginPass(passwordEncoder.encode(tbAdm.getLoginPass()));
        return mapper.tbAdmAdd(tbAdm);
    }

    @Override
    public int tbAdmUpdate(TbAdm tbAdm) {
        return mapper.tbAdmUpdate(tbAdm);
    }

    @Override
    public int tbAdmTelCount(TbAdm tbAdm) {
        return mapper.tbAdmTelCount(tbAdm);
    }

    @Override
    public int confirmLoginName(String loginName, String adminTel) {

        return mapper.confirmLoginName(loginName, adminTel);
    }

    @Override
    public int lastLogin(String lastLogin, String adminId) {
        return mapper.lastLogin(lastLogin, adminId);
    }

    @Override
    public int tbAdmDeleteFalse(Integer adminId) {
        return mapper.tbAdmDeleteFalse(adminId);
    }

    @Override
    public int tbAdmDeleteTrue(Integer adminId) {
        return mapper.tbAdmDeleteTrue(adminId);
    }

    @Override
    public PageInfo<TbAdm> tbAdmList(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<TbAdm> tbAdmList = mapper.tbAdmList();
        return new PageInfo<>(tbAdmList);
    }
}
